package cn.example.controller;

import cn.example.exception.AppException;
import cn.example.exception.AppExceptionCodeMsg;
import cn.example.pojo.Food;
import cn.example.query.FoodQuery;
import cn.example.service.IFoodService;
import cn.example.vo.ResultBean;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "餐品的API",description = "餐品相关的CRUD功能")
@RestController
@RequestMapping("/food")
public class FoodController extends BaseController<Food, FoodQuery>{

    @Autowired
    IFoodService foodService;

    @GetMapping("/business/{bid}")
    public ResultBean getByBusinessId(@PathVariable("bid") Integer bid){
        

        if(bid == null || bid == 0){
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }
        List<Food> foodList = foodService.getByBusinessId(bid);
        return ResultBean.SUCCESS(foodList);

    }
}
